package com.dingwei.lesyndrome.adapter;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dingwei.lesyndrome.R;
import com.dingwei.lesyndrome.app.MyApplication;
import com.dingwei.lesyndrome.bean.CircleDetailsBean;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.lihao.baselibrary.base.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created time 2018/3/6.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class CircleCommentAdapter extends RecyclerArrayAdapter<CircleDetailsBean.DataBean.CommentListBean> {
    public interface onCommentInterFace {
        void  onComment(int position);
        void onHead(int position);
    }
    private onCommentInterFace onCommentInterfaceListener;
        public void onCommentInterfaceListener(onCommentInterFace listener){
            onCommentInterfaceListener = listener;

        }



    public CircleCommentAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new CircleCommentHolder(parent);
    }

    public class CircleCommentHolder extends BaseViewHolder<CircleDetailsBean.DataBean.CommentListBean> {


        @Bind(R.id.img_head)
        ImageView imgHead;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.img_comment)
        ImageView imgComment;
        @Bind(R.id.tv_date)
        TextView tvDate;
        @Bind(R.id.tv_content)
        TextView tvContent;
        @Bind(R.id.tv_line)
        TextView tvLine;

        public CircleCommentHolder(ViewGroup parent) {
            super(parent, R.layout.item_circle_comment);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void setData(CircleDetailsBean.DataBean.CommentListBean data) {
            super.setData(data);

            Glide.with(BaseActivity.context)
                    .load(data.showHportrait)
                    .apply(MyApplication.headOptions)
                    .into(imgHead);
            if (TextUtils.isEmpty(data.showName)) {
               tvName.setText("暂无昵称");
            } else {
                tvName.setText(data.showName);
            }
            tvContent.setText(data.content);
            tvDate.setText(data.showTime);
            imgComment.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onCommentInterfaceListener!=null){
                        onCommentInterfaceListener.onComment(getDataPosition());
                    }
                }
            });
            imgHead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onCommentInterfaceListener!=null){
                        onCommentInterfaceListener.onHead(getDataPosition());
                    }
                }
            });

        }
    }
}
